package com.fau.hm.service.impl;

import java.util.List;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.fau.hm.entity.MedicalLog;
import com.fau.hm.service.ILogManagerService;

/**
 * 日志管理Service实现类
 * @author dangjh
 * 2014年4月29日 上午10:13:00
 */
@Service
@Transactional(readOnly = true)
public class LogManagerService extends BaseService implements ILogManagerService {

	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void insertLog(MedicalLog log) {
		this.iBaseDao.saveObject(log);
	}

	@SuppressWarnings("unchecked")
	@Override
	public String findUserLastLoginTime(String userName) {
		List<MedicalLog> log = this.iBaseDao.getBySql("from MedicalLog a where a.userName=? order by a.logTime desc",1,userName);
		if( null != log && log.size() > 0) {
			String date = DateFormatUtils.format(log.get(0).getLogTime(),"yyyy年MM月dd日 HH时mm分ss秒");
			return date;
		} else{
			return null;
		}
	}

}